

package it.cnr.icib.xsbjdbc; 


import it.cnr.icib.daopattern.DAOFactory;

import java.lang.reflect.Modifier;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
/**
 *
 * @author nino
 */
public class Example01_SqlLite {

    /**
     * @param args the command line arguments
     * @throws ClassNotFoundException 
     * @throws IllegalAccessException 
     * @throws InstantiationException 
     * @throws SQLException 
     */
	
	Statement stat;
	ResultSet rs;
	
	public Example01_SqlLite() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException{
		System.out.println(System.getProperty("user.dir"));
    	
        SqlLiteDAO_TaskModel d = (SqlLiteDAO_TaskModel) DAOFactory.getDAOFactory(Class.forName("it.cnr.icib.xsbjdbc.SqlLiteDAO_TaskModel"));
        //SqlLiteDAO_TaskModel d = (SqlLiteDAO_TaskModel) DAOFactory.getDAOFactory(DAOFactory.SQLLite, DAOFactory.getCanonicalNameOfClass("SqlLiteDAO_TaskModel"));
        
         stat = SqlLiteDAO_TaskModel.getStatement();
        //stat.executeUpdate("insert into TaskModel (domain, description) VALUES ('Gandhi', 'Mahatma')");

        //rs = stat.executeQuery("select * from TaskModel");
        //System.out.println(rs);
	}
	
	public void query() throws SQLException{
		rs = stat.executeQuery("select * from TaskModel");
        System.out.println(rs);
		
	}
	
	public void getElem() throws SQLException{
		 if (rs.next()) {
	            System.out.print("id = " + rs.getInt("id"));
	            System.out.print ("  --  domain = " + rs.getString("domain"));
	            System.out.println("  --  description = " + rs.getString("description"));
	        }
	}
	
	
    public static void main(String[] args) throws SQLException, ClassNotFoundException, InstantiationException, InstantiationException, InstantiationException, IllegalAccessException {
        // TODO code application logic here
        
       // Dispatcher.AddTaskModel();
    	
    	System.out.println(System.getProperty("user.dir"));
    	
        SqlLiteDAO_TaskModel d = (SqlLiteDAO_TaskModel) DAOFactory.getDAOFactory(Class.forName("it.cnr.icib.xsbjdbc.SqlLiteDAO_TaskModel"));
        //SqlLiteDAO_TaskModel d = (SqlLiteDAO_TaskModel) DAOFactory.getDAOFactory(DAOFactory.SQLLite, DAOFactory.getCanonicalNameOfClass("SqlLiteDAO_TaskModel"));
        
        Statement stat = SqlLiteDAO_TaskModel.getStatement();
        //stat.executeUpdate("insert into TaskModel (domain, description) VALUES ('Gandhi', 'Mahatma')");

        ResultSet rs = stat.executeQuery("select * from TaskModel");
        System.out.println(rs);
        
        while (rs.next()) {
            System.out.print("id = " + rs.getInt("id"));
            System.out.print ("  --  domain = " + rs.getString("domain"));
            System.out.println("  --  description = " + rs.getString("description"));
        }

        System.out.println();System.out.println();System.out.println();
        
                
                
        
    }
}
